package com.aaa.service.fpa.impl;

import com.aaa.dao.fpa.ViewStatisticsDao;
import com.aaa.entity.fpa.ResultDiv;
import com.aaa.entity.fpa.ViewTestResultFpa;
import com.aaa.service.fpa.ViewStatisticsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author ：chenang（731712841@qq.com）
 * @date ：Created in 2022/9/6 10:35
 * @description：
 * @modified By：
 * @version:
 */
@Service
public class ViewStatisticsServiceImpl implements ViewStatisticsService {
    @Autowired
    ViewStatisticsDao viewStatisticsDao;
    public Map<String, Integer> queryAll() {
        List<ViewTestResultFpa> fpas = viewStatisticsDao.queryAllPlanFpa();
        int r = 0, y = 0, b = 0, g = 0, f = 0;
        for (ViewTestResultFpa fpa : fpas) {
            int red = fpa.getRedCount();
            int yellow = fpa.getYellowCount();
            int blue = fpa.getBlueCount();
            Long green = fpa.getGreenCount();
            if (red > yellow && red > blue && red > green) {
                r++;
            } else if (yellow > red && yellow > blue && yellow > green) {
                y++;
            } else if (blue > red && blue > yellow && blue > green) {
                b++;
            } else if (green > red && green > yellow && green > blue) {
                g++;
            } else {
                f++;
            }
        }
        Map<String, Integer> map = new HashMap<>();
        map.put("r", r);
        map.put("y", y);
        map.put("b", b);
        map.put("g", g);
        map.put("f", f);
        return map;
    }


    /**
     * 根据ID查询对信息
     * @param
     * @return
     */
    @Override
    public Map<String, Object> queryById(Integer id) {
        List<ViewTestResultFpa> fpas = this.viewStatisticsDao.queryResultFapById(id);
        Map<String, Object> map = new HashMap();
        for (ViewTestResultFpa fpa : fpas) {
            map.put("redCount",fpa.getRedCount());
            map.put("blueCount",fpa.getBlueCount());
            map.put("greenCount",fpa.getGreenCount());
            map.put("yellowCount",fpa.getYellowCount());
        }
        return map;
    }
    @Override
    public List<ResultDiv> queryAllResultDiv(Integer id) {
        return viewStatisticsDao.queryAllDiv(id);
    }


}
